package com.laxcen.smoke.dao;

import com.laxcen.smoke.dto.res.ResourceListRes;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

@Mapper
@Repository
public interface ResourceDao {

    @Insert("insert into sys_resources(name,type,url,permission,parent_id,sort,external,available,create_time) values(#{name},#{type},#{url},#{permission},#{parentid},#{sort},#{external},#{available},#{createtime})")
    int insert(String name, String type, String url, String permission, long parentid, int sort, int external, int available, Date createtime);

    @Update("update sys_resources set name = #{name},type = #{type},url = #{url},permission = #{permission},parent_id = #{parentid},sort = #{sort},external = #{external},available = #{available},update_time = #{updatetime} where id = #{id}")
    int update(long id, String name, String type, String url, String permission, long parentid, int sort, int external, int available, Date updatetime);

    @Delete("delete from sys_resources where id = #{id}")
    int delete(long id);

    @Delete("delete from sys_role_resources where resources_id = #{id}")
    int deleteRoleAndResource(long id);

    @Select("select id,name,type,url,permission,parent_id parentid,sort,external,available from sys_resources")
    List<ResourceListRes> getResourceAllList();

    @Select("select id,name,type,url,permission,parent_id parentid,sort,external,available from sys_resources where name like CONCAT('%',#{name},'%')")
    List<ResourceListRes> getResourceListByName(String name);

}
